package com.hd.trans.widgets.views.floatwindow.component;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;

/**
 * 监听屏幕宽高变化的广播接收器
 */
public class ConfigurationChangedReceiver extends BroadcastReceiver {

    public static final IntentFilter ConfigurationChangedFilter;

    static {
        ConfigurationChangedFilter = new IntentFilter();
        ConfigurationChangedFilter.addAction(Intent.ACTION_CONFIGURATION_CHANGED);
    }

    private final OnConfigurationChangedListener onConfigurationChangedListener;

    public ConfigurationChangedReceiver(OnConfigurationChangedListener onConfigurationChangedListener) {
        this.onConfigurationChangedListener = onConfigurationChangedListener;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        if (action.equals(Intent.ACTION_CONFIGURATION_CHANGED)){
            if (onConfigurationChangedListener != null)
                onConfigurationChangedListener.onChanged();
        }
    }

    public interface OnConfigurationChangedListener{
        void onChanged();
    }

}